﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DeVetma.admin.classes;
using DeVetma.admin.models.database.metadata;
using DeVetma.admin.models.database;
using DeVetma.admin.models.entities;
using ClothesType = DeVetma.admin.models.entities.Clothes.ClothesType;

namespace DeVetma.admin.models.managers
{
    public class ClothesManager : DataManager<Clothes>
    {
        public override string ensureKey(Clothes entity)
        {
            List<Clothes> clothes = getAll();

            int len = (clothes.Count < 1 ? 1 : ((int)Math.Log10(clothes.Count)) + 2);
            entity.cID = Utilities.randomizeNumericString(len);
            while (clothes.Exists(q => q.cID == entity.cID))
                entity.cID = Utilities.randomizeNumericString(len);

            return entity.cID;
        }

        public List<Clothes> getByClothesType(ClothesType ctype)
        {
            return getAll().Where(q => q.cType == q.type(ctype)).ensure();
        }

        public List<Clothes> getMaleClothes()
        {
            return getAll().Where(q => q.cType == q.type(ClothesType.ManShirts) ||
                q.cType == q.type(ClothesType.ManShorts) || q.cType ==
                q.type(ClothesType.ManTrousers)).ensure();
        }

        public List<Clothes> getFemaleClothes()
        {
            return getAll().Where(q => 
                q.cType == q.type(ClothesType.WomanDress) ||
                q.cType == q.type(ClothesType.WomanShorts) || 
                q.cType == q.type(ClothesType.WomanSkirts) || 
                q.cType == q.type(ClothesType.WomanTops)).ensure();
        }
    }
}